﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;
using System.Text.RegularExpressions;

namespace CSMF
{
    public partial class HollywoodDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                Hollywood info = HollywoodManager.GetHollywoodByID(id);
                litTitle.Text = info.Title;
                litDate.Text = info.UploadDate.ToString("yyyy.MM.dd");
                string neirong = Regex.Replace(Convert.ToString(info.VideoContent), "<[^>]*>", "").ToString();
                litVideoContent.Text = neirong.Length > 70 ? neirong.Substring(0, 69) + "..." : neirong;
                if (info.Count.ToString().Length == 4)
                {
                    litCount.Text = info.Count.ToString().Substring(0, 1) + "," + info.Count.ToString().Substring(1);
                }
                else
                {
                    litCount.Text = info.Count.ToString();
                }


                Team team = TeamManager.GetTeamByID(info.TeamID);
                imgAuthor.ImageUrl = "UpLoad/teamImage/" + team.TeamPhoto;
                litAuthor.Text = team.Title;

                BindVideoTeam(info.TeamID);
                BindVideoLast();
                BindVideo(id);

                HollywoodManager.ModifyHollywoodCount(id, (info.Count + 1));
            }
        }

        protected string GetVideo(int id)
        {
            int ids = Convert.ToInt32(Request.QueryString["id"]);
            string location;
            if (Request.QueryString["vid"] == null)
            {
                HollywoodLoaction lo = HollywoodLoactionManager.GetHollywoodLoactionByIDAndH(1, ids);
                location = lo.Location;
            }
            else
            {
                int vid = Convert.ToInt32(Request.QueryString["vid"]);
                HollywoodLoaction lo = HollywoodLoactionManager.GetHollywoodLoactionByID(vid);
                location = lo.Location;
            }
            return location;
        }

        protected void BindVideo(int id)
        {
            IList<HollywoodLoaction> video = HollywoodLoactionManager.GetHollywoodLoactionsByHollywoodID(id);
            rptIcon.DataSource = video;
            rptIcon.DataBind();
        }

        protected string GetImage(int id)
        {
            Icon icon = IconManager.GetIconByID(id);
            return icon.Image;
        }

        protected void BindVideoTeam(int id)
        {
            IList<Hollywood> video = HollywoodManager.GetHollywoodsByTeamID(id);
            rptVideoLike.DataSource = video;
            rptVideoLike.DataBind();
        }

        protected void BindVideoLast()
        {
            IList<Hollywood> video = HollywoodManager.GetHollywoodsLast();
            rptVideoLast.DataSource = video;
            rptVideoLast.DataBind();
        }
    }
}
